package com.ruoyi.app.controller.user;

import com.ruoyi.app.business.account.LaborAccountBusiness;
import com.ruoyi.app.business.project.ProjectBusiness;
import com.ruoyi.app.business.user.UserBusiness;
import com.ruoyi.app.domain.account.LaborAccount;
import com.ruoyi.app.domain.labor.LaborInfo;
import com.ruoyi.app.domain.labor.LaborInfoDetail;
import com.ruoyi.app.domain.my.LaborMy;
import com.ruoyi.app.domain.project.ProjectSimple;
import com.ruoyi.common.core.utils.CommonUtils;
import com.ruoyi.common.core.web.domain.APIResult;
import com.ruoyi.common.core.web.page.CommonPageInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.service.account.query.LaborAccountQuery;
import com.ruoyi.service.project.query.ProjectQueryForDemander;
import com.ruoyi.service.user.query.LaborPopQuery;
import com.ruoyi.service.user.query.LaborQuery;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 劳务方用户
 *
 * @author Zane
 * @since 2025-09-27
 */
@RestController
@RequestMapping("/labor/")
public class LaborController {

  @Resource
  private UserBusiness userBusiness;
  @Resource
  private ProjectBusiness projectBusiness;
  @Resource
  private LaborAccountBusiness laborAccountBusiness;

  /**
   * 劳务方列表
   */
  @PostMapping("list")
  public TableDataInfo<LaborInfo> list(@Validated @RequestBody LaborQuery laborQuery) {
    CommonPageInfo<LaborInfo> laborInfos = userBusiness.listLabor(laborQuery);
    return CommonUtils.buildTableData(laborInfos);
  }

  /**
   * 劳务方选择列表(未封禁)
   */
  @PostMapping("select")
  public APIResult<List<LaborInfo>> select(@Validated @RequestBody LaborPopQuery popQuery) {
    List<LaborInfo> laborInfos = userBusiness.selectLabor(popQuery);
    return APIResult.success(laborInfos);
  }

  /**
   * 项目leader(未封禁,认证的)
   */
  @PostMapping("selectProjectLeader")
  public APIResult<List<LaborInfo>> selectProjectLeader(
      @Validated @RequestBody LaborPopQuery popQuery) {
    List<LaborInfo> laborInfos = userBusiness.selectProjectLeader(popQuery);
    return APIResult.success(laborInfos);
  }

  /**
   * 劳务方明细
   */
  @GetMapping("detail")
  public APIResult<LaborInfoDetail> detail(@RequestParam("userId") Long userId) {
    LaborInfoDetail laborInfo = userBusiness.detail(userId);
    return APIResult.success(laborInfo);
  }
  /**
   * 我的页面
   */
  @PostMapping("myInfo")
  public APIResult<LaborMy> laborMyInfo() {
    LaborMy laborMy = userBusiness.laborMyInfo();
    return APIResult.success(laborMy);
  }
  /**
   * 已完成项目列表
   */
  @PostMapping("/project/finish")
  public TableDataInfo<ProjectSimple> projectFinish(
      @Validated @RequestBody ProjectQueryForDemander projectQuery) {
    CommonPageInfo<ProjectSimple> projects = projectBusiness.laborListForFinish(projectQuery);
    return CommonUtils.buildTableData(projects);
  }

  /**
   * 已报名项目列表
   */
  @PostMapping("/project/forApply")
  public TableDataInfo<ProjectSimple> forApply(
      @Validated @RequestBody ProjectQueryForDemander projectQuery) {
    CommonPageInfo<ProjectSimple> projects = projectBusiness.laborListForApply(projectQuery);
    return CommonUtils.buildTableData(projects);
  }
  /**
   * 执行中项目列表
   */
  @PostMapping("/project/forExecution")
  public TableDataInfo<ProjectSimple> forExecution(
      @Validated @RequestBody ProjectQueryForDemander projectQuery) {
    CommonPageInfo<ProjectSimple> projects = projectBusiness.laborListForExecution(projectQuery);
    return CommonUtils.buildTableData(projects);
  }

  /**
   * 收支记录
   */
  @PostMapping("/accountList")
  public TableDataInfo<LaborAccount> accountList(
      @Validated @RequestBody LaborAccountQuery query) {
    CommonPageInfo<LaborAccount> accountList = laborAccountBusiness.accountList(query);
    return CommonUtils.buildTableData(accountList);
  }

}
